import i18n from '@/locales'
import { TableColumns } from '@/components/TableContainer'
const columnsElements = [
	[
		{
			prefix: i18n.t('common.strict_provide'),
			suffix: 'RebatePlatform'
		},
		{
			prefix: i18n.t('common.agent_provide'),
			suffix: 'Rebate'
		}
	],
	[
		{
			prefix: i18n.t('common.components.rebate'),
			suffix: 'Rebate'
		},
		{
			prefix: i18n.t('common.components.share'),
			suffix: 'Zhancheng'
		}
	]
]
const filterSummary4 = (value) => {
	if (typeof value !== 'number') return '-'
	const valueStr = value.toString()
	const dotIndex = valueStr.indexOf('.')
	const finalValue =
		dotIndex !== -1
			? valueStr.substring(0, valueStr.indexOf('.') + 5) - 0
			: value
	return `${finalValue.toLocaleString('en-us', {
		maximumFractionDigits: 4
	})}%`
}
const lineRender = (prefix, value, key) => (
	<div key={key}>
		{prefix}: {value < 0 ? '-' : filterSummary4(value)}
	</div>
)
const multiAgentRender = ({ row, column }) =>
	row.status === 0
		? '-'
		: columnsElements[1].map((item, index) => {
				return lineRender(
					item.prefix,
					row[`${column.property}${item.suffix}`],
					index
				)
		  })

const multiMemberRender = ({ row, column }) =>
	columnsElements[0].map((item, index) =>
		lineRender(item.prefix, row[`${column.property}${item.suffix}`], index)
	)

// 公共column
export const columns = (isMember, isExpiredLogs) => {
	return [
		{
			label: i18n.t('common.serial_number'),
			width: '60px',
			customRender: ({ $index }) => {
				return $index + 1
			}
		},
		{
			label: i18n.t('agent.agent_account'),
			isShow: !isMember,
			prop: 'userName'
		},
		{
			label: '会员账号',
			isShow: isMember,
			prop: 'userName'
		},
		{
			label: i18n.t('agent.agent_level'),
			prop: 'proxyLevel',
			customRender: ({ row }) => {
				if (row.userType === 0 || isMember)
					return i18n.t('common.member')
				return row.proxyLevel.toString()
			}
		},
		{
			label: i18n.t('common.belong_merchant'),
			prop: 'merchantName'
		},
		{
			label: i18n.t('agent.total_agent_account'),
			prop: 'topProxyName'
		},
		{
			label: i18n.t('common.top_agent'),
			prop: 'parentProxyName'
		},
		{
			prop: 'texas',
			header: () => '德州俱乐部分成',
			customRender: isMember
				? multiMemberRender
				: ({ row, column }) =>
						row.status === 0
							? '-'
							: lineRender(
									'分成',
									row[`${column.property}Rebate`],
									`${column.property}Rebate`
							  )
		},
		{
			prop: 'texasInsurance',
			header: () => '德州保险分成',
			isShow: !isMember,
			customRender: isMember
				? multiMemberRender
				: ({ row, column }) =>
						row.status === 0
							? '-'
							: lineRender(
									'分成',
									row[`${column.property}Rebate`],
									`${column.property}Rebate`
							  )
		},
		{
			prop: 'valueAddedService',
			header: () => '德州增值服务分成',
			isShow: !isMember,
			customRender: isMember
				? multiMemberRender
				: ({ row, column }) =>
						row.status === 0
							? '-'
							: lineRender(
									'分成',
									row[`${column.property}Rebate`],
									`${column.property}Rebate`
							  )
		},
		{
			header: () => i18n.t('common.game_video'),
			prop: 'actualPerson',
			customRender: isMember ? multiMemberRender : multiAgentRender
		},
		{
			header: () => i18n.t('common.game_sports'),
			prop: 'sports',
			customRender: isMember ? multiMemberRender : multiAgentRender
		},
		{
			header: () => i18n.t('common.game_lottery'),
			prop: 'lotteryTicket',
			customRender: isMember ? multiMemberRender : multiAgentRender
		},
		{
			header: () => i18n.t('common.game_poker'),
			prop: 'chess',
			customRender: isMember ? multiMemberRender : multiAgentRender
		},
		{
			header: () => i18n.t('common.game_e_sports'),
			prop: 'esports',
			customRender: isMember ? multiMemberRender : multiAgentRender
		},
		{
			header: () => i18n.t('common.game_electronic'),
			prop: 'electronic',
			customRender: isMember ? multiMemberRender : multiAgentRender
		},

		TableColumns.status({
			minWidth: 80,
			texts: {
				0: '未设置',
				1: '已生效',
				2: '已失效',
				3: '平台调整'
			}
		}),
		{
			label: i18n.t('friendInvitation.modify_time'),
			prop: 'updatedAt',
			minWidth: 170
		},
		{
			label: i18n.t('agent.modified_account'),
			prop: 'updatedBy'
		},
		{
			label: '失效时间',
			prop: 'lostEffectDt'
		}
	]
}
